package o;

import android.content.Context;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;

public final class hk {
    private final a ˋ;

    interface a {
        boolean ˊ(MotionEvent motionEvent);
    }

    static class c implements a {
        private static final int ˏॱ = ViewConfiguration.getTapTimeout();
        private static final int ॱˊ = ViewConfiguration.getDoubleTapTimeout();
        private static final int ᐝ = ViewConfiguration.getLongPressTimeout();
        private int ʻ;
        private float ʻॱ;
        private int ʼ;
        private float ʼॱ;
        private int ʽ;
        private VelocityTracker ʽॱ;
        private float ʾ;
        private boolean ˈ;
        OnDoubleTapListener ˊ;
        private boolean ˊॱ;
        MotionEvent ˋ;
        private boolean ˋॱ;
        final OnGestureListener ˎ;
        boolean ˏ;
        private final Handler ͺ;
        boolean ॱ;
        private boolean ॱˋ;
        private float ॱˎ;
        private int ॱॱ;
        private boolean ॱᐝ;
        private MotionEvent ᐝॱ;

        class b extends Handler {
            final /* synthetic */ c ॱ;

            b(c cVar) {
                this.ॱ = cVar;
            }

            b(c cVar, Handler handler) {
                this.ॱ = cVar;
                super(handler.getLooper());
            }

            public void handleMessage(Message message) {
                switch (message.what) {
                    case 1:
                        this.ॱ.ˎ.onShowPress(this.ॱ.ˋ);
                        return;
                    case 2:
                        this.ॱ.ˏ();
                        return;
                    case 3:
                        if (this.ॱ.ˊ == null) {
                            return;
                        }
                        if (this.ॱ.ॱ) {
                            this.ॱ.ˏ = true;
                            return;
                        } else {
                            this.ॱ.ˊ.onSingleTapConfirmed(this.ॱ.ˋ);
                            return;
                        }
                    default:
                        throw new RuntimeException("Unknown message " + message);
                }
            }
        }

        c(Context context, OnGestureListener onGestureListener, Handler handler) {
            if (handler != null) {
                this.ͺ = new b(this, handler);
            } else {
                this.ͺ = new b(this);
            }
            this.ˎ = onGestureListener;
            if (onGestureListener instanceof OnDoubleTapListener) {
                ˎ((OnDoubleTapListener) onGestureListener);
            }
            ॱ(context);
        }

        private void ॱ(Context context) {
            if (context == null) {
                throw new IllegalArgumentException("Context must not be null");
            } else if (this.ˎ == null) {
                throw new IllegalArgumentException("OnGestureListener must not be null");
            } else {
                this.ˈ = true;
                ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
                int scaledTouchSlop = viewConfiguration.getScaledTouchSlop();
                int scaledDoubleTapSlop = viewConfiguration.getScaledDoubleTapSlop();
                this.ॱॱ = viewConfiguration.getScaledMinimumFlingVelocity();
                this.ʽ = viewConfiguration.getScaledMaximumFlingVelocity();
                this.ʼ = scaledTouchSlop * scaledTouchSlop;
                this.ʻ = scaledDoubleTapSlop * scaledDoubleTapSlop;
            }
        }

        public void ˎ(OnDoubleTapListener onDoubleTapListener) {
            this.ˊ = onDoubleTapListener;
        }

        public boolean ˊ(MotionEvent motionEvent) {
            int i;
            int action = motionEvent.getAction();
            if (this.ʽॱ == null) {
                this.ʽॱ = VelocityTracker.obtain();
            }
            this.ʽॱ.addMovement(motionEvent);
            boolean z = (action & 255) == 6;
            int actionIndex = z ? motionEvent.getActionIndex() : -1;
            int pointerCount = motionEvent.getPointerCount();
            float f = 0.0f;
            float f2 = 0.0f;
            for (i = 0; i < pointerCount; i++) {
                if (actionIndex != i) {
                    f2 += motionEvent.getX(i);
                    f += motionEvent.getY(i);
                }
            }
            actionIndex = z ? pointerCount - 1 : pointerCount;
            f2 /= (float) actionIndex;
            f /= (float) actionIndex;
            boolean hasMessages;
            float yVelocity;
            float xVelocity;
            switch (action & 255) {
                case 0:
                    if (this.ˊ != null) {
                        hasMessages = this.ͺ.hasMessages(3);
                        if (hasMessages) {
                            this.ͺ.removeMessages(3);
                        }
                        if (this.ˋ == null || this.ᐝॱ == null || !hasMessages || !ˎ(this.ˋ, this.ᐝॱ, motionEvent)) {
                            this.ͺ.sendEmptyMessageDelayed(3, (long) ॱˊ);
                        } else {
                            this.ॱᐝ = true;
                            actionIndex = (this.ˊ.onDoubleTap(this.ˋ) | 0) | this.ˊ.onDoubleTapEvent(motionEvent);
                            this.ॱˎ = f2;
                            this.ʾ = f2;
                            this.ʻॱ = f;
                            this.ʼॱ = f;
                            if (this.ˋ != null) {
                                this.ˋ.recycle();
                            }
                            this.ˋ = MotionEvent.obtain(motionEvent);
                            this.ˋॱ = true;
                            this.ॱˋ = true;
                            this.ॱ = true;
                            this.ˊॱ = false;
                            this.ˏ = false;
                            if (this.ˈ) {
                                this.ͺ.removeMessages(2);
                                this.ͺ.sendEmptyMessageAtTime(2, (this.ˋ.getDownTime() + ((long) ˏॱ)) + ((long) ᐝ));
                            }
                            this.ͺ.sendEmptyMessageAtTime(1, this.ˋ.getDownTime() + ((long) ˏॱ));
                            return actionIndex | this.ˎ.onDown(motionEvent);
                        }
                    }
                    actionIndex = 0;
                    this.ॱˎ = f2;
                    this.ʾ = f2;
                    this.ʻॱ = f;
                    this.ʼॱ = f;
                    if (this.ˋ != null) {
                        this.ˋ.recycle();
                    }
                    this.ˋ = MotionEvent.obtain(motionEvent);
                    this.ˋॱ = true;
                    this.ॱˋ = true;
                    this.ॱ = true;
                    this.ˊॱ = false;
                    this.ˏ = false;
                    if (this.ˈ) {
                        this.ͺ.removeMessages(2);
                        this.ͺ.sendEmptyMessageAtTime(2, (this.ˋ.getDownTime() + ((long) ˏॱ)) + ((long) ᐝ));
                    }
                    this.ͺ.sendEmptyMessageAtTime(1, this.ˋ.getDownTime() + ((long) ˏॱ));
                    return actionIndex | this.ˎ.onDown(motionEvent);
                case 1:
                    this.ॱ = false;
                    MotionEvent obtain = MotionEvent.obtain(motionEvent);
                    if (this.ॱᐝ) {
                        hasMessages = this.ˊ.onDoubleTapEvent(motionEvent) | 0;
                    } else if (this.ˊॱ) {
                        this.ͺ.removeMessages(3);
                        this.ˊॱ = false;
                        hasMessages = false;
                    } else if (this.ˋॱ) {
                        hasMessages = this.ˎ.onSingleTapUp(motionEvent);
                        if (this.ˏ && this.ˊ != null) {
                            this.ˊ.onSingleTapConfirmed(motionEvent);
                        }
                    } else {
                        VelocityTracker velocityTracker = this.ʽॱ;
                        int pointerId = motionEvent.getPointerId(0);
                        velocityTracker.computeCurrentVelocity(1000, (float) this.ʽ);
                        yVelocity = velocityTracker.getYVelocity(pointerId);
                        xVelocity = velocityTracker.getXVelocity(pointerId);
                        hasMessages = (Math.abs(yVelocity) > ((float) this.ॱॱ) || Math.abs(xVelocity) > ((float) this.ॱॱ)) ? this.ˎ.onFling(this.ˋ, motionEvent, xVelocity, yVelocity) : false;
                    }
                    if (this.ᐝॱ != null) {
                        this.ᐝॱ.recycle();
                    }
                    this.ᐝॱ = obtain;
                    if (this.ʽॱ != null) {
                        this.ʽॱ.recycle();
                        this.ʽॱ = null;
                    }
                    this.ॱᐝ = false;
                    this.ˏ = false;
                    this.ͺ.removeMessages(1);
                    this.ͺ.removeMessages(2);
                    return hasMessages;
                case 2:
                    if (this.ˊॱ) {
                        return false;
                    }
                    xVelocity = this.ॱˎ - f2;
                    yVelocity = this.ʻॱ - f;
                    if (this.ॱᐝ) {
                        return false | this.ˊ.onDoubleTapEvent(motionEvent);
                    }
                    if (this.ˋॱ) {
                        i = (int) (f2 - this.ʾ);
                        int i2 = (int) (f - this.ʼॱ);
                        i = (i * i) + (i2 * i2);
                        if (i > this.ʼ) {
                            hasMessages = this.ˎ.onScroll(this.ˋ, motionEvent, xVelocity, yVelocity);
                            this.ॱˎ = f2;
                            this.ʻॱ = f;
                            this.ˋॱ = false;
                            this.ͺ.removeMessages(3);
                            this.ͺ.removeMessages(1);
                            this.ͺ.removeMessages(2);
                        } else {
                            hasMessages = false;
                        }
                        if (i > this.ʼ) {
                            this.ॱˋ = false;
                        }
                        return hasMessages;
                    } else if (Math.abs(xVelocity) < 1.0f && Math.abs(yVelocity) < 1.0f) {
                        return false;
                    } else {
                        boolean onScroll = this.ˎ.onScroll(this.ˋ, motionEvent, xVelocity, yVelocity);
                        this.ॱˎ = f2;
                        this.ʻॱ = f;
                        return onScroll;
                    }
                case 3:
                    ˎ();
                    return false;
                case 5:
                    this.ॱˎ = f2;
                    this.ʾ = f2;
                    this.ʻॱ = f;
                    this.ʼॱ = f;
                    ॱ();
                    return false;
                case 6:
                    this.ॱˎ = f2;
                    this.ʾ = f2;
                    this.ʻॱ = f;
                    this.ʼॱ = f;
                    this.ʽॱ.computeCurrentVelocity(1000, (float) this.ʽ);
                    int actionIndex2 = motionEvent.getActionIndex();
                    actionIndex = motionEvent.getPointerId(actionIndex2);
                    f2 = this.ʽॱ.getXVelocity(actionIndex);
                    float yVelocity2 = this.ʽॱ.getYVelocity(actionIndex);
                    for (actionIndex = 0; actionIndex < pointerCount; actionIndex++) {
                        if (actionIndex != actionIndex2) {
                            int pointerId2 = motionEvent.getPointerId(actionIndex);
                            if ((this.ʽॱ.getYVelocity(pointerId2) * yVelocity2) + (this.ʽॱ.getXVelocity(pointerId2) * f2) < 0.0f) {
                                this.ʽॱ.clear();
                                return false;
                            }
                        }
                    }
                    return false;
                default:
                    return false;
            }
        }

        private void ˎ() {
            this.ͺ.removeMessages(1);
            this.ͺ.removeMessages(2);
            this.ͺ.removeMessages(3);
            this.ʽॱ.recycle();
            this.ʽॱ = null;
            this.ॱᐝ = false;
            this.ॱ = false;
            this.ˋॱ = false;
            this.ॱˋ = false;
            this.ˏ = false;
            if (this.ˊॱ) {
                this.ˊॱ = false;
            }
        }

        private void ॱ() {
            this.ͺ.removeMessages(1);
            this.ͺ.removeMessages(2);
            this.ͺ.removeMessages(3);
            this.ॱᐝ = false;
            this.ˋॱ = false;
            this.ॱˋ = false;
            this.ˏ = false;
            if (this.ˊॱ) {
                this.ˊॱ = false;
            }
        }

        private boolean ˎ(MotionEvent motionEvent, MotionEvent motionEvent2, MotionEvent motionEvent3) {
            if (!this.ॱˋ || motionEvent3.getEventTime() - motionEvent2.getEventTime() > ((long) ॱˊ)) {
                return false;
            }
            int x = ((int) motionEvent.getX()) - ((int) motionEvent3.getX());
            int y = ((int) motionEvent.getY()) - ((int) motionEvent3.getY());
            if ((x * x) + (y * y) < this.ʻ) {
                return true;
            }
            return false;
        }

        void ˏ() {
            this.ͺ.removeMessages(3);
            this.ˏ = false;
            this.ˊॱ = true;
            this.ˎ.onLongPress(this.ˋ);
        }
    }

    static class d implements a {
        private final GestureDetector ॱ;

        d(Context context, OnGestureListener onGestureListener, Handler handler) {
            this.ॱ = new GestureDetector(context, onGestureListener, handler);
        }

        public boolean ˊ(MotionEvent motionEvent) {
            return this.ॱ.onTouchEvent(motionEvent);
        }
    }

    public hk(Context context, OnGestureListener onGestureListener) {
        this(context, onGestureListener, null);
    }

    public hk(Context context, OnGestureListener onGestureListener, Handler handler) {
        if (VERSION.SDK_INT > 17) {
            this.ˋ = new d(context, onGestureListener, handler);
        } else {
            this.ˋ = new c(context, onGestureListener, handler);
        }
    }

    public boolean ॱ(MotionEvent motionEvent) {
        return this.ˋ.ˊ(motionEvent);
    }
}
